package models

import "time"
import (
	_ "github.com/mattn/go-sqlite3"
	"github.com/Unknwon/com"
	"os"
	"path"
	"github.com/astaxie/beego/orm"
)

const (
	_DBName = "data/beeblog.db"
	_DriverName = "sqlite3"
)

type Category struct {
	Id int64
	Title string
	CreateTime time.Time `orm:"index"`
	Views int64 `orm:"index"`
	TopicTime time.Time `orm:"index"`
	TopicCount int64
	TopicLastUserId int64
}

//文章
type Topic struct {
	Id int64
	Uid int64
	Title string
	Content string `orm:"size(5000)"`
	Attachment string
	CreateTime time.Time `orm:"index"`
	UpdateTime time.Time `orm:"index"`
	Views int64 `orm:"index"`
	Author string
	ReplyTime time.Time
	ReplyCount int64
	ReplyLastUid int64
}

func RegisterDB(){
	if !com.IsExist(_DBName){
		os.MkdirAll(path.Dir(_DBName),os.ModePerm)
		os.Create(_DBName)
	}

	orm.RegisterModel(new(Topic),new(Category))
	orm.RegisterDriver(_DriverName,orm.DRSqlite)
	orm.RegisterDataBase("default",_DriverName,_DBName,10)
}